#! /bin/bash
./termux-install.sh
status=$?
if [ "$status" -eq 0 ]; then
	zsh_autosuggestions_dir="/data/data/com.termux/files/home/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
	if [ -d "$zsh_autosuggestions_dir" ]; then
		echo "目录 zsh-autosuggestions 已经存在！"
		status_1=$?
	else
		git clone https://gitee.com/aiba51/zsh-autosuggestions.git "$zsh_autosuggestions_dir"
		status_1=$?
	fi
	if [ "$status_1" -eq 0 ]; then
		zshrc="/data/data/com.termux/files/home/.zshrc"
		old_1='ZSH_THEME="agnoster"'
		new_1='ZSH_THEME="random"'
		old_2="plugins=(git)"
		new_2="plugins=(git zsh-autosuggestions)"
		if cat "$zshrc" | grep -q "$new_1" && grep -q "$new_2"; then
			echo "zshrc 文件已经是最新设置！"
		else
			echo "正在设置 zshrc 文件..."
			sed -i -e "s|$old_1|$new_1|" -e "s|$old_2|$new_2|" "$zshrc"
		fi
	else
		echo -e "zsh-autosuggestions 插件克隆失败！\n请重试！"
		exit 1
	fi
else
	echo -e "ohmyzsh安装失败！\n请重试！"
	exit 1
fi
